package com.kingdee.pda.ui.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.kingdee.pda.R;

/**
 * 处理中dialog
 * Created by zhanlg
 * DATE 2019/6/4
 * TIME 9:06
 */

public class LoadingDialog extends BaseAlertDialog<LoadingDialog> implements View.OnClickListener{

    private Context mContext;
    private View mView;
    private TextView mTvContent;
    private Button mButton;

    private String mContent;
    private onCancelClickedListener mOnCancelListener;

    public LoadingDialog(@NonNull Context context, String content) {
        super(context);
        this.mContext = context;
        this.mContent = content;
    }

    @Override
    public View onCreateView() {
        mView = LayoutInflater.from(mContext).inflate(R.layout.dialog_loading, null);
        mLlContainer.addView(mView);
        setCanceledOnTouchOutside(false);
        initView();
        initData();
        return mLlContainer;
    }

    private void initView() {
        mTvContent = mView.findViewById(R.id.tv_content);
        mButton = mView.findViewById(R.id.button);
        mButton.setOnClickListener(this);
    }

    private void initData() {
        mTvContent.setText(mContent);
    }


    public void setContent(String content) {
        mTvContent.setText(content);
    }

    public void setOnCancelListener(onCancelClickedListener listener) {
        this.mOnCancelListener = listener;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                dismiss();
                if (mOnCancelListener != null) {
                    mOnCancelListener.cancel();
                }
                break;
        }
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();//屏蔽返回键取消dialog
    }

    public interface onCancelClickedListener {
        void cancel();
    }
}
